package com.cdtu.entity;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

@TableName(value ="topic")
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Topic implements Serializable {

    /**
     * 题序
     */
    private Integer index;
    /**
     * 题目
     */
    private String title;
    /**
     * 类型（0单选，1多选，2判断）
     */
    private Integer type;
    /**
     * 选项（A-G）默认填充Null
     */
//    private String A;
//    private String B;
//    private String C;
//    private String E;
//    private String F;
//    private String G;
    /**
     * 答案
     */
    //private String answer;
    /**
     * 解析
     */
    private String analysis;
    private boolean correct=false;
    /**
     * 图片地址
     */
    private String imageSrc;
    //判断题是否完成
    boolean isChecked = false;

    private static final long serialVersionUID = 1L;

    private List<Option> option;

    private List<String> answerArray;

    public Topic(boolean isChecked) {
        this.isChecked = isChecked;
    }


    public void setCorrect(boolean correct) {
        this.correct = correct;
    }

    public Topic(Integer index, String title, Integer type, List<Option> option, String answer, String analysis, String imageSrc) {
        this.index = index;
        this.title = title;
        this.type = type;
        this.analysis = analysis;
        this.imageSrc = imageSrc;
        this.option = option;
        this.answerArray = answerChars(answer);
    }
    public Topic(Integer index, String title, Integer type, List<Option> option, String answer, String analysis) {
        this.index = index;
        this.title = title;
        this.type = type;
        this.analysis = analysis;
        this.option = option;
        this.answerArray = answerChars(answer);
    }


    public static List<String> answerChars(String answer){
        List<String> list = new ArrayList<>();
        for (int i = 0; i < answer.length(); i++) {
            String substring = answer.substring(i, i + 1);
            list.add(substring);
        }
        return list;
    }

}
